package com.freak.neteasecloudmusic.modules.find.recommend.base.adapter;

import android.content.Context;
import android.graphics.Rect;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.freak.neteasecloudmusic.R;
import com.freak.neteasecloudmusic.modules.find.recommend.base.entity.NewSongBaseEntity;

import java.util.List;

public class NewSongBaseAdapter extends BaseQuickAdapter<NewSongBaseEntity, BaseViewHolder> {
    private Context context;
    public final static int NEW_SONG_ITEM = 0;


    public NewSongBaseAdapter(int layoutResId, @Nullable List<NewSongBaseEntity> data, Context context) {
        super(layoutResId, data);
        this.context = context;
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, NewSongBaseEntity item) {

        RecyclerView recyclerView = helper.getView(R.id.recyclerViewNewSongBase);
        recyclerView.setLayoutManager(new LinearLayoutManager(context));
        NewSongAdapter  newSongAdapter = new NewSongAdapter(item.getResultBeans(), context);
        newSongAdapter.bindToRecyclerView(recyclerView);
        recyclerView.addItemDecoration(new RecyclerView.ItemDecoration() {
            @Override
            public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
                super.getItemOffsets(outRect, view, parent, state);
                if (parent.getChildLayoutPosition(view) != item.getResultBeans().size()) {
                    outRect.top = 20;
                }
            }
        });
        recyclerView.setAdapter(newSongAdapter);
    }
}
